﻿#region Author

/**********************************************************************
 * Created by : wangyifei@shanghai3h.com
 * Create Date: 2008/03/7
 * Description: 所有页面的基类
 * Samples	  :
 * 
 **********************************************************************/

#endregion

using System;
using System.Web;
using System.Web.UI;
using Platform.Http;

public class BasePage : Page
{
    #region Event

    protected override void OnInit(EventArgs e)
    {
        #region InitCSS

        //string[] CSSs ={
        //    "Default.css",
        //    "gridStyle.css",
        //    "multiPage.css",
        //    "splitterStyle.css",
        //    "subModal.css",
        //    "tabStyle.css",
        //    "treeStyle.css",
        //    "ui.tabs.css", 
        //};
        //string path = VirtualPathUtility.ToAbsolute("~/App_Themes/Default");
        //foreach (string current in CSSs)
        //{
        //    this.Header.Controls.Add(new LiteralControl("\r\n<link href=\"" + path + "/" + current + "\" type=\"text/css\" rel=\"stylesheet\" />\r\n"));
        //}

        #endregion

        #region InitJavascript

        var currentTimeKey = "?" + DateTime.Now.Ticks; //防止ie缓存
        //jquery
        //   this.Header.Controls.Add(new LiteralControl("\r\n<script src=\"" + VirtualPathUtility.ToAbsolute("~/js/jquery.js") + "\" type=\"text/javascript\"></script>\r\n"));
        Header.Controls.Add(new LiteralControl("\r\n<script src=\"" +
                                               VirtualPathUtility.ToAbsolute("~/js/jquery-1.11.1.min.js") +
                                               "\" type=\"text/javascript\"></script>\r\n"));

        //formValidator
        //   this.Header.Controls.Add(new LiteralControl("\r\n<script src=\"" + VirtualPathUtility.ToAbsolute("~/js/formValidator.js") + "\" type=\"text/javascript\"></script>\r\n"));

        //formValidatorRegex
        //   this.Header.Controls.Add(new LiteralControl("\r\n<script src=\"" + VirtualPathUtility.ToAbsolute("~/js/formValidatorRegex.js") + "\" type=\"text/javascript\"></script>\r\n"));

        //ui.tabs.pack
        // this.Header.Controls.Add(new LiteralControl("\r\n<script src=\"" + VirtualPathUtility.ToAbsolute("~/js/ui.tabs.pack.js") + "\" type=\"text/javascript\"></script>\r\n"));

        #region subModal using SelectGoods (Invalid)

        ////subModal_common
        //this.Header.Controls.Add(new LiteralControl("\r\n<script src=\"" + VirtualPathUtility.ToAbsolute("~/js/subModal_common.js") + "\" type=\"text/javascript\"></script>\r\n"));

        ////subModal
        //this.Header.Controls.Add(new LiteralControl("\r\n<script src=\"" + VirtualPathUtility.ToAbsolute("~/js/subModal.js") + "\" type=\"text/javascript\"></script>\r\n")); 

        #endregion

        //EnterToTab
        //     this.Header.Controls.Add(new LiteralControl("\r\n<script src=\"" + VirtualPathUtility.ToAbsolute("~/js/EnterToTab.js") + "\" type=\"text/javascript\"></script>\r\n"));

        //common
        Header.Controls.Add(new LiteralControl("\r\n<script src=\"" + VirtualPathUtility.ToAbsolute("~/js/common.js") +
                                               currentTimeKey + "\" type=\"text/javascript\"></script>\r\n"));

        //controlButton 
        // this.Header.Controls.Add(new LiteralControl("\r\n<script src=\"" + VirtualPathUtility.ToAbsolute("~/JS/ControlButton.js")  + "\" type=\"text/javascript\"></script>\r\n"));

        #region JValidate On Form Submit (Invalid)

        #endregion

        #endregion

        base.OnInit(e);

        if (Session["_UserName"] == null)
            Response.Write("<script>alert('会话已过期,请重新登录');location='/';</script>");
    }

    #endregion

    #region Property

    /// <summary>
    ///     用户账号
    /// </summary>
    public string UserAccount
    {
        get { return Base.UserAccount; }
    }

    /// <summary>
    ///     用户名称
    /// </summary>
    public string UserName
    {
        get { return Base.UserName; }
    }

    /// <summary>
    ///     用户密码
    /// </summary>
    public string PWS
    {
        get { return Base.PWS; }
    }

    /// <summary>
    ///     用户UserID
    /// </summary>
    public int UserID
    {
        get { return Base.UserID; }
    }

    /// <summary>
    ///     自增量ID
    /// </summary>
    public int? IdentityID
    {
        get
        {
            int? pid = null;

            #region Get QueryString pid

            var stringpid = "";

            #region 得到pid(当url为www.XXX.com/aaa.aspx?8888888 时，Platform.Http.UrlHelper.GetValue 就会异常，所以在这里catch一下)

            try
            {
                stringpid = UrlHelper.GetValue("pid");
            }
            catch
            {
            }

            #endregion

            if (string.IsNullOrEmpty(stringpid))
                pid = null;
            else
                pid = Convert.ToInt32(stringpid);

            #endregion

            return ViewState["IdentityID"] == null ? pid : (int) ViewState["IdentityID"];
        }
        set { ViewState["IdentityID"] = value; }
    }

    /// <summary>
    ///     GridView当前页
    /// </summary>
    public int? GVPageSize
    {
        get
        {
            int? size = null;

            #region Get QueryString pid

            var stringsize = "";

            #region 得到pid(当url为www.XXX.com/aaa.aspx?8888888 时，Platform.Http.UrlHelper.GetValue 就会异常，所以在这里catch一下)

            try
            {
                stringsize = UrlHelper.GetValue("size");
            }
            catch
            {
            }

            #endregion

            if (string.IsNullOrEmpty(stringsize))
                size = null;
            else
                size = Convert.ToInt32(stringsize);

            #endregion

            return ViewState["GVPageSize"] == null ? size : (int) ViewState["GVPageSize"];
        }
        set { ViewState["GVPageSize"] = value; }
    }


    /// <summary>
    ///     用于得到当前状态
    /// </summary>
    /// <returns></returns>
    public GridViewStatus Status
    {
        get
        {
            if (ViewState["GridViewStatus"] == null)
                ViewState["GridViewStatus"] = GridViewStatus.Init;
            return (GridViewStatus) ViewState["GridViewStatus"];
        }
        set { ViewState["GridViewStatus"] = value; }
    }

    #endregion
}